package com.zhs.smartmall.order.service.impl;


import com.zhs.smartmall.order.model.UndoLog;
import com.zhs.smartmall.order.dao.UndoLogDao;
import com.zhs.smartmall.order.service.IUndoLogService;
import com.zhs.smartmall.order.dto.UndoLogDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author zhenghuisheng
 * @since 2023-11-12
 */
@Service
@Slf4j
public class UndoLogServiceImpl extends ServiceImpl< UndoLogDao, UndoLog> implements IUndoLogService {

    @Resource
    private UndoLogDao undoLogDao;

    @Override
    @Transactional
    public R addOrUpdate(UndoLogDto undoLogDto) {
        if (BeanUtil.isEmpty(undoLogDto)) throw new ServiceException("数据不能为空");
        UndoLog undoLog = new UndoLog();
        BeanUtil.copyProperties(undoLogDto,undoLog);
        if (undoLogDto.getId() == null){
            undoLogDao.insert(undoLog);
            return R.ok("数据插入成功");
        }else {
            undoLogDao.updateById(undoLog);
            return R.ok("数据更新成功");
        }
    }
}